package com.wc.codeforces.思维.Maximum_Sum;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/22 17:31
 * @description https://codeforces.com/problemset/problem/1946/B
 */
public class Main {
    /**
     * 找到最大的一个连续子区间和maxs，然后一直在这个子区间里面添加，就是最大，
     * 如果该子区间为小于0那就不添加是最好的
     * 也就可以是前缀和的思想，找到前面最小的一个值相减就好了
     * 时间复杂度O(n)
     * k次操作，依次增加 maxs, maxs * 2, maxs * 4,... maxs * (2 ^ k - 1)
     * 将所有增加的加起来答案就是 res = maxs * (2 ^ k - 1) + s[n],
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010, P = (int) 1e9 + 7;
    static long[] s = new long[N];
    static int n, k;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            k = sc.nextInt();
            for (int i = 1; i <= n; i++) s[i] = s[i - 1] + sc.nextInt();
            long minv = 0, maxs = 0;
            for (int i = 1; i <= n; i++) {
                maxs = Math.max(s[i] - minv, maxs);
                minv = Math.min(s[i], minv);
            }
            if (maxs == 0) out.println(mod(s[n]));
            else {
                out.println(mod(mod(s[n]) + maxs % P * qkm(2, k) - maxs));
            }
        }
        out.flush();
    }
    // 负数%成正数
    static long mod(long x) {
        return (x % P + P) % P;
    }

    // 快速幂
    static long qkm(long a, int b) {
        long res = 1;
        while (b > 0) {
            if ((b & 1) == 1) res = res * a % P;
            b >>= 1;
            a = a * a % P;
        }
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
